<?php
/**
 * Created by PhpStorm.
 * User: hoter.zhang
 * Date: 2016/10/6
 * Time: 9:18
 */

namespace app\core\components;


use Yii;

class HttpUtil
{

    public $type = 'dir';

    public $path;

    public function __construct(){
        $this->path = dirname(Yii::$app->basePath);
    }


    public static function getUrl($image_url){
        $image_url = rawurlencode($image_url);
        //http%3A%2F%2Fimage.gameapps.hk%2Fimages%2F201610%2F04%2FSASA2.jpg
        $image_url = str_replace(['http%3A%2F%2Fimage.gameapps.hk%2F','%2F'], ['http://image.gameapps.hk/','/'], $image_url);
        return $image_url;
    }

    public static function get_curl_contents($url,$header=0,$nobody=0,$ipopen=0){
        if(!function_exists('curl_init')) die('php.ini未开启php_curl.dll');
        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_HEADER, $header);
        curl_setopt($c, CURLOPT_NOBODY, $nobody);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($c, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($c, CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($c,CURLOPT_REFERER,'http://image.gameapps.hk/');
        $ipopen==0&&curl_setopt($c, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$_SERVER["REMOTE_ADDR"], 'CLIENT-IP:'.$_SERVER["REMOTE_ADDR"]));
        $content = curl_exec($c);
        curl_close($c);
        return $content;
    }



}